//
//  XSJLiveBroadcastTableCell.m
//  XSJ
//
//  Created by yuanyuan he on 2020/5/9.
//  Copyright © 2020 apple. All rights reserved.
//

#import "XSJLiveBroadcastTableCell.h"
#import "JXLayoutButton.h"

@interface XSJLiveBroadcastTableCell()

@property (nonatomic, strong) JXLayoutButton *agreeButton;
@property (nonatomic, strong) UIButton*privacyButton;

@end

@implementation XSJLiveBroadcastTableCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self setup];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setup
{
    self.contentView.backgroundColor = ColorHex(0xffffff);
    [self.contentView addSubview:self.agreeButton];
    [self.contentView addSubview:self.privacyButton];

    [_agreeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(25);
        make.left.mas_equalTo(30);
    }];
    
    [_privacyButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_agreeButton.mas_right);
        make.centerY.equalTo(self->_agreeButton);
    }];

}

-(void)agreeButtonDidClick:(UIButton *)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(XSJLiveBroadcastTableCellDidClick:)])
    {
        [self.delegate XSJLiveBroadcastTableCellDidClick:1];
    }
    sender.selected = !sender.isSelected;
}


-(void)privacyButtonDidClick
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(XSJLiveBroadcastTableCellDidClick:)])
    {
        [self.delegate XSJLiveBroadcastTableCellDidClick:2];
    }
}

- (UIButton *)agreeButton {
    if (_agreeButton == nil) {
        _agreeButton = [JXLayoutButton buttonWithType:UIButtonTypeCustom];
        [_agreeButton setTitle:@"我已阅读并同意" forState:UIControlStateNormal];
        [_agreeButton setImage:[UIImage imageNamed:@"Check on"] forState:UIControlStateNormal];
        [_agreeButton setImage:[UIImage imageNamed:@"Check off"] forState:UIControlStateSelected];
        [_agreeButton setTitleColor:ColorHex(0x000000) forState:UIControlStateNormal];
        _agreeButton.titleLabel.font = [UIFont systemFontOfSize:11];
        _agreeButton.layoutStyle = JXLayoutButtonStyleLeftImageRightTitle;//左图右字
        _agreeButton.midSpacing = 5.0f;
        [_agreeButton addTarget:self action:@selector(agreeButtonDidClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _agreeButton;
}

- (UIButton *)privacyButton {
    if (_privacyButton == nil) {
        _privacyButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_privacyButton setTitle:@" 《直播协议》" forState:UIControlStateNormal];
        [_privacyButton setTitleColor:ColorHex(0x3169EB) forState:UIControlStateNormal];
        _privacyButton.titleLabel.font = [UIFont systemFontOfSize:12];
        [_privacyButton addTarget:self action:@selector(privacyButtonDidClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _privacyButton;
}

@end
